package com.example.spring.ioc.base;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author lei yu
 * @date 2024/05/15
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class User {
    
    private final static Map<String,Object> CACHE = new ConcurrentHashMap<>();

    private Integer id;
    private String username;
    private String realname;

    public static void main(String[] args) {
        // spring 启动时读取配置大致流程是，创建对象，并把它放到缓存 CACHE
        User user = new User();
        user.setId(1).setRealname("real").setUsername("user");
        CACHE.put("user", user);

        // getBean() 就是通过 name 获取到对应的 CACHE
        Object o = CACHE.get("user");
        System.out.println("o = " + o);

        new User(1,"1","1");
    }

    public User setId(Integer id) {
        this.id = id;
        return this;
    }
}
